package de.farbstreich.tozen2.client;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JPanel;

public class ClientGUIGameActions extends JPanel {

	private static final long serialVersionUID = 1L;
	private JButton startButton = null;
	private JButton surrenderButton = null;
	private ClientGUIInput guiInput;
	private boolean isAdmin = false;

	/**
	 * This is the default constructor
	 */
	public ClientGUIGameActions() {
		super();
		initialize();
	}
	
	public void setInput(ClientGUIInput guiInput) {
		this.guiInput = guiInput;
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.gridx = 1;
		gridBagConstraints1.insets = new Insets(5, 5, 5, 5);
		gridBagConstraints1.gridy = 0;
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.insets = new Insets(5, 5, 5, 5);
		gridBagConstraints.gridy = 0;
		this.setLayout(new GridBagLayout());
		this.setSize(300, 200);
		this.add(getStartButton(), gridBagConstraints);
		this.add(getSurrenderButton(), gridBagConstraints1);
	}

	public void setAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}
	
	public boolean isAdmin() {
		return isAdmin;
	}
	
	public void enableStartButton() {
		getStartButton().setEnabled(isAdmin);
	}
	
	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getStartButton() {
		if (startButton == null) {
			startButton = new JButton();
			startButton.setText("Spiel starten");
			Formator.formateButton(startButton, 100);
			startButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					assert guiInput == null : "ClientGUIGameAction StartButton Error: no GUI input";
					guiInput.sendStartGame();
				}
			});
		}
		return startButton;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSurrenderButton() {
		if (surrenderButton == null) {
			surrenderButton = new JButton();
			surrenderButton.setText("aufgeben");
			Formator.formateButton(surrenderButton, 100);
			surrenderButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					assert guiInput == null : "ClientGUIGameAction SurrenderGameButton Error: no GUI input";
					guiInput.sendSurrenderGame();
				}
			});
		}
		return surrenderButton;
	}

}
